Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to adjust merging behavior of configs per fields defined in configurations #152

Merged
merged 9 commits into from
Feb 20, 2020

Conversation

blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Feb 13, 2020

Adds the ability to adjust merging behavior of configs per fields defined in configurations.

Below is the user experience that this change provides:

cfg.Merge(
   other,
   ucfg.FieldReplaceValues("paths"),
   ucfg.FieldAppendValues("processors"),
)

This would allow a paths field to be replaced with any values from other and the processors field to be appended with values from other. Indexes into arrays can also be used to adjust the merging behavior at that index in the array (eg. FieldAppendValues("processors.2.add_tags.tags").

In the case that the depths of the fields are unknown but that behavior should always occur when fields of that name are reached in the merging process then the **.{name} selector can be used.

ucfg.FieldReplaceValues("**.paths") will ensure that replace is always performed when a field name paths is reached no matter its depth in the configuration. Nesting of wildcard is also supported with say "subpath.**.paths".

Closes #151

@blakerouse blakerouse requested a review from urso February 13, 2020 21:47
@blakerouse
Copy link
Contributor Author

@urso This is just a first pass at the idea. It needs more tests to ensure that all cases are covered. Wanted to get some opinion on it before I go to far.

@blakerouse blakerouse marked this pull request as ready for review February 14, 2020 16:00
@blakerouse
Copy link
Contributor Author

I have added many tests and updated the description of the pull request, I think this is ready for a real review.

merge.go Outdated Show resolved Hide resolved
merge.go Outdated Show resolved Hide resolved
merge.go Outdated Show resolved Hide resolved
opts.go Outdated Show resolved Hide resolved
@urso
Copy link

urso commented Feb 18, 2020

Having a **, we might also introduce a simple * here. All in all the field names resemble glob patterns.

…rt for referencing entries in arrays by index.
@blakerouse
Copy link
Contributor Author

@urso Have a look now. Using Config to compute a tree on how to perform the merging.

merge.go Outdated Show resolved Hide resolved
opts.go Outdated Show resolved Hide resolved
opts.go Show resolved Hide resolved
opts.go Outdated Show resolved Hide resolved
… to only allocation options when absolutely required.
@Bamieh
Copy link
Member

Bamieh commented Feb 19, 2020

Codecov Report

Merging #152 into master will increase coverage by 0.36%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #152      +/-   ##
==========================================
+ Coverage   78.35%   78.71%   +0.36%     
==========================================
  Files          24       24              
  Lines        2730     2800      +70     
==========================================
+ Hits         2139     2204      +65     
- Misses        434      435       +1     
- Partials      157      161       +4     
Impacted Files Coverage Δ
merge.go 81.65% <0.00%> (-0.49%) ⬇️
types.go 74.84% <0.00%> (+0.61%) ⬆️
getset.go 86.41% <0.00%> (+6.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab69586...6352512. Read the comment docs.

@blakerouse
Copy link
Contributor Author

@urso Updated to address your comments. If you could give it another look, thanks!

@blakerouse blakerouse merged commit 5f065f8 into elastic:master Feb 20, 2020
@blakerouse blakerouse deleted the merge-config-per-field branch February 20, 2020 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to control the merging behavior of maps and arrays when merging configs
4 participants